﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace IOExtensions
{
    class Support
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public static List<string> GetFilesRecursive(string b)
        {
            List<string> result = new List<string>();
            Stack<string> stack = new Stack<string>();
            stack.Push(b);
            while (stack.Count > 0)
            {
                string directory = stack.Pop();

                try
                {
                    result.AddRange(Directory.GetFiles(directory));

                    foreach (string directoryNode in Directory.GetDirectories(directory))
                    {
                        stack.Push(directoryNode);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                }
                catch (PathTooLongException)
                {
                }
                catch (DirectoryNotFoundException)
                {
                }
            }

            return result;
        }
    }
}
